package com.lh.music.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lh.music.R;
import com.lh.music.entity.Album;

import java.util.List;

/**
 * Created by a on 2016/12/14.
 */

public class AlbumAdapter extends BaseAdapter {
    private Context context;
    private List<Album> mData;

    public AlbumAdapter(Context context, List<Album> mData) {
        this.context = context;
        this.mData = mData;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null){
            convertView= LayoutInflater.from(context)
                    .inflate(R.layout.adapter_singer,null);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        holder.name.setText(mData.get(position).getAlbumName());
        holder.count.setText(mData.get(position).getSongList().size()+"首"+" "+mData.get(position).getArtist());
        return convertView;
    }
    static class ViewHolder{
        TextView name;
        TextView count;
        public ViewHolder(View view){
            name= (TextView) view.findViewById(R.id.name);
            count= (TextView) view.findViewById(R.id.count);
        }
    }
}
